<?php

//栏目分类设置
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

$_POST['id'] = array_unique((array)$_POST['id']);
if (count($_POST['id']) < 1) {
  err('参数出错！<br />问题分析：<br />1、您可能未选择<br />2、参数传递出错');
}
@ require ('writable/set/set_area.php');
@ require ('readonly/function/write_file.php');

if ($_POST['limit'] == 'del') {
  if ($file = @file('writable/__temp__/newsite_list.txt')) {
    foreach ((array)$_POST['id'] as $id) {
      unset($file[abs($id)]);
	}
    write_file('writable/__temp__/newsite_list.txt', @implode('', (array)$file));
    alert('执行成功。', 'webmaster_central.php?get=newsite');
  } else {
    err('文件writable/__temp__/newsite_list.txt已读不到数据');
  }


} elseif ($_POST['limit'] == 'pass') {
  if (!isset($sql['db_err'])) {
    $db = db_conn();
  }
  if ($sql['db_err'] != '') {
    err($sql['db_err']);
  }

  $new10 = array();
  $new10_file = (array)@file('writable/require/newsite10.txt');

  $file = (array)@file('writable/__temp__/newsite_list.txt');


  foreach ($_POST['id'] as $id) {
    //if... 此处应加安全判断，但由于是管理员自操作，免了
    list($column_id, $class_id) = @explode('_', $_POST['siteclass'][$id]);
	$arrc[$id] = 'column_id='.$column_id.'&class_id='.$class_id.'';
    $reset[$_POST['siteclass'][$id]] = 1;

    $result = db_query($db, 'SELECT http_name_style FROM '.$sql['pref'].''.$sql['data']['承载网址数据的表名'].' WHERE column_id="'.$column_id.'" AND class_id="'.$class_id.'" AND class_title LIKE "'.$_POST['sitetitle'][$id].'|%" AND detail_title="" LIMIT 1');
    $row = db_fetch($db, $result);
    $result = NULL;

    $new_line = preg_replace("/".preg_quote($_POST['siteurl'][$id], "/")."[^\n]+\|\n/iU", "", $row['http_name_style']);
	$new_line = $new_line.$_POST['siteurl'][$id]."|".$_POST['sitename'][$id]."||\n";

    db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET http_name_style="'.addslashes($new_line).'" WHERE column_id="'.$column_id.'" AND class_id="'.$class_id.'" AND class_title LIKE "'.$_POST['sitetitle'][$id].'|%" AND detail_title=""');


	$new10[] = "<li>[<a href=\"class.php?column_id=".$column_id."&class_id=".$class_id."\">".$web["area"][$column_id][$class_id][0]."</a>] <a href=\"".$_POST['siteurl'][$id]."\">".$_POST['sitename'][$id]."</a></li>\n";
    unset($new_line, $column_id, $class_id, $row);
	unset($file[abs($id)]);
  }
  db_close($db);

  $new10 = @array_merge($new10, $new10_file);
  $new10 = @array_unique($new10);
  $new10 = @array_filter($new10);
  $new10 = @array_slice($new10, 0, 10);
  write_file('writable/require/newsite10.txt', @implode('', $new10));
  write_file('writable/__temp__/newsite_list.txt', @implode('', $file));
  unset($id);


  foreach((array)$reset as $key => $val) {
    list($_GET['column_id'], $_GET['class_id']) = @explode('_', $key);
    reset_indexhtml('class.php', $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html');
    unset($key, $val);
  }

  echo '<img src="readonly/images/ok.gif" /> 新站申录批准成功！<br /><span style="background-color:#FF6600;color:#FFFFFF;">下面群发邮件通知</span>';
  @ob_flush();
@flush();

  /*
  发送邮件-------------------
  */
  if ($_POST['mailto'] == 1) {
    if (!@file_exists('readonly/function/mail_class.php')) {
      err('邮件发送功能未安装！请联系<a href="http://www.162100.com/" target="_blank">162100.com</a>官方定制');
    }
    if (count($_POST['email']) > 0) {
      @ require ('readonly/function/mail_class.php');
      $subject = "恭喜：您网站的收录请求已经通过";
      $subject = "=?UTF-8?B?".base64_encode($subject)."?="; //此行解决utf-8编码邮件标题乱码
      foreach ($_POST['id'] as $id){
        $body = '　　您于'.$_POST['date'][$id].'向<a href="'.$web['path'].'" target="_blank">'.$web['sitename2'].'</a>提交的网站['.$_POST['siteurl'][$id].' - '.$_POST['sitename'][$id].']已通过审核，成功被收录。<br />　　收录页面为：<a href="'.$web['path'].'class.php?'.$arrc[$id].'#class_title_new" target="_blank">'.$web['path'].'class.php?'.$arrc[$id].'</a>及<a href="'.$web['path'].''.$web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html" target="_blank">'.$web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html</a><br />　　在此也欢迎光临<a href="'.$web['path'].'" target="_blank">'.$web['sitename'].'</a>';
        $to = $_POST['email'][$id]; //收件人 
        $send = $smtp -> sendmail($to, $web['sender'], $subject, $body, $web['mailtype']);
        if ($send == 1) { 
          echo '<br />邮件['.$to.']发送成功！';
        } else { 
          echo '<br />邮件['.$to.']发送失败！原因：邮箱密码未设置或出错'; 
        }
        @ob_flush();
@flush();


      }
    } else {
      err('邮箱为空！');
    }
  }
  alert('群发邮件通知成功！', 'webmaster_central.php?get=newsite');


} else {
  err('命令错误！');
}




?>